#!/bin/bash 

E_MC_INLCUDE_ARGSLIB=65
E_MC_INLCUDE_ARGSLIB_MSG="Impossibile includere argslib.sh"
E_MC_INLCUDE_LOGLIB=66
E_MC_INLCUDE_LOGLIB_MSG="Impossibile includere loglib.sh"

G_LOGPOS=$(basename $0)
#G_RMIC_FILES=( 	database.DBServer \
#		parcmanserver.ParcmanServer \
#		loginserver.LoginServer \
#		indexingserver.IndexingServer \
#		parcmanclient.ParcmanClient )
G_RMIC_FILES=(	parcmanserver.ParcmanServer \
		loginserver.LoginServer \
        indexingserver.IndexingServer)
G_PUBLIC_HTML=$HOME/public_html/common/
G_CODEBASE_FILES=(	parcmanserver/RemoteParcmanServer.class \
			parcmanserver/RemoteParcmanServerUser.class \
			parcmanserver/ClientDataUser.class \
			loginserver/RemoteLoginServer.class \
			remoteexceptions/*.class \
			parcmanclient/*.class \
			remoteclient/*.class \
			parcmanagent/*.class \
			parcmanagent/exceptions/*.class \
			pshell/*.class \
			indexingserver/RemoteIndexingServer.class \
			indexingserver/RemoteIndexingServerAgent.class \
			database/beans/*.class \
			database/exceptions/*.class \
			logserver/*.class \
			io/IOColor.class \
			io/Logger.class \ 
			io/LoggerConstants.class \
			io/LoggerLevel.class \
			io/LoggerProperties.class \
			io/Pair.class \ 
			io/PropertyManager.class \
			io/exceptions/InOutException.class \
			io/exceptions/ListIsEmptyException.class \
			plog/PLog.class )

# include argslib.sh
. ../bash/argslib.sh 2> /dev/null
[[ $? -gt 0 ]] && echo $E_MC_INLCUDE_ARGSLIB_MSG && exit $E_MC_INLCUDE_ARGSLIB

# include loglib.sh
. ../bash/loglib.sh 2> /dev/null
[[ $? -gt 0 ]] && echo $E_MC_INLCUDE_LOGLIB_MSG && exit $E_MC_INLCUDE_LOGLIB


bt_info "rm -rf $G_PUBLIC_HTML/*" "RMIC CLEANING" $G_LOGPOS

bt_info_inline "RMIC COMPILING" $G_LOGPOS
echo 
for f in ${G_RMIC_FILES[@]}; do
	#echo "rmic -d $G_PUBLIC_HTML $f"
	bt_info "rmic -d $G_PUBLIC_HTML $f" "compile '$f'" $G_LOGPOS 
done

echo 

bt_info_inline "MOVING CLASS FILES TO CODEBASE" $G_LOGPOS
echo 
for f in ${G_CODEBASE_FILES[@]}; do
	[[ ! -d $G_PUBLIC_HTML$(dirname $f) ]] && bt_info "mkdir -p $G_PUBLIC_HTML$(dirname $f)" "mkdir '$G_PUBLIC_HTML$(dirname $f)'" $G_LOGPOS 
	bt_info "cp $f $G_PUBLIC_HTML$(dirname $f)/" "copy '$f'" $G_LOGPOS 1
done
